import { Controller, Post, Body } from "@nestjs/common";
import { ApiRes, RequsetUser, UsePermGuard, definePermission } from "src/decorator";
import { MediaService } from "../service/media.service";
import { MediaAddDto, MediaQueryDto, MediaRemoveDto, MediaUpdateDto } from "src/dto/media";
import { ApiOperation, ApiTags } from "@nestjs/swagger";
import { MediaEntity } from "src/entity";

const Perm = definePermission("user:media", {
    query: {
        name: "查询",
        code: "query",
        description: "用户播放记录查询权限",
    },
    add: {
        name: "添加",
        code: "add",
        description: "用户播放记录添加权限",
    },
    update: {
        name: "更新",
        code: "update",
        description: "用户播放记录更新权限",
    },
    remove: {
        name: "移除",
        code: "remove",
        description: "用户播放记录移除权限",
    },
} as const);

@ApiTags("User - 模块", "Media - 模块")
@Controller("user")
export class MediaController {
    constructor(private readonly mediaService: MediaService) {}

    @ApiOperation({ summary: "播放记录列表" })
    @ApiRes({ type: MediaEntity, pagination: true })
    @UsePermGuard(Perm.QUERY)
    @Post("query_media")
    queryMedia(@RequsetUser("id") id: number, @Body() media: MediaQueryDto) {
        return this.mediaService.query(id, media);
    }

    @ApiOperation({ summary: "添加播放记录" })
    @ApiRes({ type: MediaEntity })
    @UsePermGuard(Perm.ADD)
    @Post("add_media")
    addMedia(@RequsetUser("id") id: number, @Body() media: MediaAddDto) {
        return this.mediaService.add(id, media);
    }

    @ApiOperation({ summary: "更新播放记录" })
    @UsePermGuard(Perm.UPDATE)
    @Post("update_media")
    updateMedia(@RequsetUser("id") id: number, @Body() media: MediaUpdateDto) {
        return this.mediaService.update(id, media);
    }

    @ApiOperation({ summary: "移除播放记录" })
    @UsePermGuard(Perm.REMOVE)
    @Post("remove_media")
    removeMedia(@RequsetUser("id") id: number, @Body() media: MediaRemoveDto) {
        return this.mediaService.remove(id, media);
    }
}
